//
// Created by Bili_TianX_Computer on 2021/7/8.
//

#include "Product.h"

Product::Product(const QString &name, double purchasePrice, double sellingPrice, unsigned int stock,
                 const QString &unit) : name(name), purchasePrice(purchasePrice), sellingPrice(sellingPrice),
                                        stock(stock), unit(unit)
{}

Product::Product(QJsonObject obj) :
        name(obj["name"].toString()),
        purchasePrice(obj["purchasePrice"].toDouble()),
        sellingPrice(obj["sellingPrice"].toDouble()),
        stock(obj["stock"].toInt()),
        unit(obj["unit"].toString())
{

}

QJsonObject Product::toJsonObject()
{
    QJsonObject obj;
    obj.insert("name", name);
    obj.insert("purchasePrice", purchasePrice);
    obj.insert("sellingPrice", sellingPrice);
    obj.insert("stock", static_cast<int>(stock));
    obj.insert("unit", unit);
    return obj;
}

bool Product::operator==(const Product &rhs) const
{
    return name == rhs.name;
}

bool Product::operator!=(const Product &rhs) const
{
    return !(rhs == *this);
}
